package com.sgl.blog.service.impl;

import com.sgl.blog.mapper.CommentMapper;
import com.sgl.blog.pojo.BlogComment;
import com.sgl.blog.service.ArticleService;
import com.sgl.blog.service.CommentService;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;


@SuppressWarnings("SqlResolve")
@Service("commentService")
public class CommentServiceImpl implements CommentService {

    @Resource
    private JdbcTemplate jt;

    @Resource
    private CommentMapper commentMapper;

    @Resource
    private ArticleService articleService;


    @Override
    public List<Map<String, Object>> findByArticleId(Integer id) {
        return jt.queryForList("select a.account_profile_photo,a.account_nickname,a.account_id,c.comment_content,c.comment_date from blog_account a,blog_comment c  where  a.account_id = c.account_id and c.article_id = ?",id);
    }

    @Override
    public Boolean insertComment(BlogComment comment) {
        articleService.commentCountPlus(comment.getArticleId());
        return commentMapper.insert(comment) > 0;
    }

    @Override
    public Boolean deleteComment(BlogComment comment) {
        return commentMapper.delete(comment) > 0;
    }


}
